﻿using System;
using System.Collections.Generic;
using System.Text;
using RoadTeam.Enums;

namespace RoadTeam.DAL
{
    public sealed class DbFactory
    {
        private static object o = new object();
        private static DbFactory factory;

        private DbFactory() { }
        public static DbFactory CreateInstance()
        {
            if (factory==null)
                lock (o)
                    if (factory==null)
                        factory = new DbFactory();
            return factory;
        }

        private HelpBase CreateDb(String Type)
        {
            HelpBase helpbase=null;
            switch (Type)
            {
                case "SQLSERVER":
                    helpbase = new SqlHelper(); break;
                    //这里添加其他数据库支持
                default:
                    break;
            }
            if (helpbase == null)
                throw new Exception("数据库类型没有配置正确");
            return helpbase;
        }
        //添加重载
        public HelpBase CreateDb()
        {
            return CreateDb(GlobalConfig.DataDbType.ToUpper());
        }
    }
}
